home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-09-10 | 27.1 KB | 1,107 lines | [TEXT/QED1] |
-
- \ ========================================================================
- \ ========================================================================
- \ ========================================================================
- \ I/O Task with Multi-Finder modifications by Murray Anderegg.
- \ Potential users should note that this modified I/O Task
- \ is NOT official sanctioned by Palo Alto Shipping Company
- \ (PASC, the parent company of MACH 2). PASC does believe,
- \ however, that this source may be both useful and instructive
- \ to other MACH 2 programmers. We are therefore pleased
- \ (and thankful to Mr. Anderegg) to make this source code
- \ available "as is" to other users of MACH 2 ("as is" means
- \ without support from PASC).
-
- \ I/O Task High Level Code
- \ Portions (C) Copyright 1987-1988 Palo Alto Shipping Company
-
- \ ========================================================================
- \ ========================================================================
- \ ========================================================================
-
- CR .( Loading new I/O task code...) CR
-
- ONLY FORTH DEFINITIONS
- ALSO MAC
- ALSO ASSEMBLER
-
- \ ===================== WaitNextEvent definition =========================
-
- .TRAP _WaitNextEvent $A860
-
- CODE WaitNextEvent ( eventMask VAR-eventRecord sleep mouseRgn - flag )
- EXG D4,A7
- CLR.W -(A7) \ This is where we return the result.
- MOVE.W $E(A6),-(A7) \ The event mask.
- MOVE.L $8(A6),-(A7) \ The event record.
- MOVE.L $4(A6),-(A7) \ sleep
- MOVE.L (A6),-(A7) \ mouseRgn
- ADDA.W #$10,A6
- _WaitNextEvent
- MOVE.W (A7)+,D0 \ flag -> D0
- EXT.L D0 \ Extend the sign.
- MOVE.L D0,-(A6) \ Push it onto the Forth stack.
- EXG D4,A7
- RTS
- END-CODE
-
- \ ===== End WaitNextEvent Definition ====================================
-
-
- \ ===== Miscellaneous Constants ==========================================
- HEX
-
- FFFFFF86 CONSTANT screenBits \ Offset to global Quickdraw variable which
- \ holds the address of a bitmap record which
- \ describes the screen currently in use.
- 6 CONSTANT screenBounds \ Offset into a bitmap record to the bounding
- \ rectangle information.
- 08 CONSTANT portBounds \ Offset to bounding box of screen bitmap.
- 00640064 CONSTANT DiskPt
- A64 CONSTANT CurActivate \ Pointer of window to receive activate event.
- 1 CONSTANT ActivateMask
- 100 CONSTANT CommandKeyMask
- FFFFFFFF CONSTANT EveryEvent \ Recognize every event.
-
- 10 CONSTANT portRect \ Offset to window rect in grafport.
- 6C CONSTANT windowKind \ Window type field [word].
- 8C CONSTANT controlList \ Offset to control list in a window record.
- 90 CONSTANT nextWindow \ Next window in Z-ordered list.
- 9C CONSTANT GrowFlagOffset \ Offset to Mach2 "Does this window
- \ have a growbox?" flag located past the
- \ end of a window record.
- 9E CONSTANT VBarOffset \ A Mach2-generated window with a V- or
- A2 CONSTANT HBarOffset \ H-SCROLLBAR will have either the handle
- \ to the scrollbar or a 0 at these offsets
- \ to locations just past the end of a
- \ window record.
- 08 CONSTANT CtrlRectOffset \ Offset in a Mac control record to
- \ bounding rectangle for the control.
- 60 CONSTANT WNETrap# \ This is the trap number for WaitNextEvent.
- 9F CONSTANT UnkTrap# \ This is the trap number for Unimplemented.
-
- DECIMAL
- 11 CONSTANT PatBic
- 129 CONSTANT InThumb
-
-
- \ ===== Mach2 Private Global Variables ===================================
- HEX
-
- : EditHandle ( - a ) \ Address where handle to "Edit" menu
- NP 14 + ; \ is stored.
-
- : EmptyMenuBar ( - a ) \ Address where handle to an empty
- EVENT-RECORD 1E + ; \ menu is stored.
-
- Header MFThere 1 ,
-
- \ ===== EVENT-RECORD Offsets =============================================
- DECIMAL
-
- 0 CONSTANT What
- 2 CONSTANT Message
- 6 CONSTANT When
- 10 CONSTANT Where
- 14 CONSTANT Modifiers
- 16 CONSTANT WhichWindow
-
-
- \ ===== Event Codes ======================================================
- DECIMAL
-
- 0 CONSTANT Null
- 1 CONSTANT MouseDown
- 2 CONSTANT MouseUp
- 3 CONSTANT KeyDown
- 4 CONSTANT KeyUp
- 5 CONSTANT AutoKey
- 6 CONSTANT UpdateEvent
- 7 CONSTANT DiskInserted
- 8 CONSTANT ActivateEvent
-
-
- \ ===== "FindWindow" result codes ========================================
- DECIMAL
-
- 0 CONSTANT InDesk
- 1 CONSTANT InMenuBar
- 2 CONSTANT InSysWindow
- 3 CONSTANT InContent
- 4 CONSTANT InDrag
- 5 CONSTANT InGrow
- 6 CONSTANT InGoAway
- 7 CONSTANT InZoomIn
- 8 CONSTANT InZoomOut
-
-
- \ ===== User variable offsets ============================================
- DECIMAL
-
- 40 CONSTANT HeadOffset
- 44 CONSTANT TailOffset
-
- 108 CONSTANT TaskMenuBarOffset
- 116 CONSTANT MenuDataOffset
- 124 CONSTANT ControlDataOffset
- 128 CONSTANT ControlHandleOffset
- 136 CONSTANT DialogDataOffset
- 140 CONSTANT DialogHandleOffset
-
- 152 CONSTANT ContentOffset
- 156 CONSTANT DragOffset
- 160 CONSTANT GrowOffset
- 164 CONSTANT GoAwayOffset
- 168 CONSTANT UpdateOffset
- 172 CONSTANT ActivateOffset
- 190 CONSTANT DialogHookOffset
- 194 CONSTANT ZoomInOffset
- 198 CONSTANT ZoomOutOffset
- 202 CONSTANT ControlActionOffset
-
- 308 CONSTANT gInBackgroundOffset
- 304 CONSTANT SuspendResumeOffset
-
-
- \ ===== Start of Code ====================================================
- \ ========================================================================
- \ ========================================================================
-
-
- \ ===== Utility Word =====================================================
-
- CODE ScreenRect ( - rectaddr )
- MOVE.L (A5),A0
- LEA screenBits(A0),A0
- LEA screenBounds(A0),A0
- MOVE.L A0,-(A6)
- RTS
- END-CODE
-
- : gInBackground! { truthValue | homeTask nextTask -- }
- STATUS -> homeTask
- homeTask -> nextTask
- BEGIN
- truthValue nextTask 2+ gInBackgroundOffset + !
- nextTask 2+ @ -> nextTask
- nextTask homeTask =
- UNTIL
- ;
-
- \ ===== "Non-Vectorable" Default Event Handling Routines =================
-
- : Run-Desk ( - ) ;
-
- : Run-System ( - )
- EVENT-RECORD
- EVENT-RECORD WhichWindow + @
- CALL SystemClick ;
-
-
- \ ===== Processing Menu Selections =======================================
-
- : Run-Menubar { | menudata wptr taskptr flag -- }
- EVENT-RECORD Where + @ CALL MenuSelect -> menudata
-
- \ MenuSelect will return zero in the high order word
- \ if no choice is made.
- ^ menudata W@
- IF
- CALL FrontWindow -> wptr
-
- BEGIN
- \ What kind of window is frontmost ?
- \ If it's a system window (a desk accessory window)
- \ look backwards through the linked list of windows
- \ for a window which belongs to a terminal task.
- wptr windowKind + W@ L_EXT 0<
-
- \ Also make sure we haven't reached the end
- \ of the window list.
- wptr 0 <>
- AND
- WHILE
- wptr nextWindow + @ -> wptr
- REPEAT
-
- \ Once we've found a valid window, one with a
- \ window kind greater than zero, we must make
- \ sure it is a terminal window.
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ If it is a terminal window we can
- \ send it the menu selection information.
- menudata taskptr MenuDataOffset + !
- THEN
- THEN ;
-
- : DoMenuKey { | menudata wptr taskptr flag -- flag }
- 0 -> flag
- EVENT-RECORD Message + 2+ W@ CALL MenuKey -> menudata
- ^ menudata W@
- IF
- CALL FrontWindow -> wptr
- wptr
- IF
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- taskptr TaskMenuBarOffset + @
- IF
- menudata taskptr MenuDataOffset + !
- -1 -> flag
- THEN
- THEN
- THEN
- THEN
- flag ;
-
-
- \ ===== Processing Key Input =============================================
- HEX
-
- : DoKey { | taskptr head tail temp1 temp2 -- }
- CALL FrontWindow
- CALL GetWRefCon -> taskptr
- taskptr
- IF
- taskptr HeadOffset + @ -> head
- taskptr TailOffset + @ -> tail
-
- head 4+ 3F AND -> temp1 \ Inc the head position
- head FFFFFFC0 AND -> temp2 \ Get base addr of queue.
- temp1 +> temp2 \ Form new head address.
-
- \ Would the queue overflow if we added a new
- \ character at the new head address ?
- \ (is the queue full?)
- temp2 tail <>
- IF
- \ Store modifiers information in upper
- \ word of local variable.
- EVENT-RECORD Modifiers + W@ ^ temp1 W!
-
- \ Store the key information in the lower
- \ word of local variable.
- EVENT-RECORD Message + 2+ W@ ^ temp1 2+ W!
-
- \ Enqueue the key data.
- temp1 head !
-
- \ Save the new head position.
- temp2 taskptr HeadOffset + !
- ELSE
- 5 CALL SysBEEP
- THEN
- ELSE
- 5 CALL SysBEEP
- THEN ;
- DECIMAL
-
- : DoKeyDown ( - )
- EVENT-RECORD Modifiers + W@ CommandKeyMask AND
- IF
- \ Handle a command key sequence.
- DoMenuKey 0=
- IF
- DoKey
- THEN
- ELSE
- \ Handle key input.
- DoKey
- THEN ;
-
-
- \ ===== Processing Disk Events ===========================================
-
- : DoDisk ( - )
- CALL DILoad
- EVENT-RECORD Message + W@
- IF
- DiskPt
- EVENT-RECORD Message + @
- CALL DIBadMount
- DROP
- THEN
- CALL DIUnload ;
-
-
- \ ===== "Vectored" Event Handling Routines ===============================
- \ ===== (RUN-UPDATE) =====================================================
-
- : (RUN-UPDATE) { | saveport wptr -- }
- EVENT-RECORD Message + @ -> wptr
- ^ saveport CALL GetPort
- wptr CALL SetPort
-
- wptr CALL BeginUpdate
- wptr GrowFlagOffset + C@
- IF
- wptr VBarOffset + @
- wptr HBarOffset + @ OR
- 0=
- IF
- \ If there is just a growbox, set pen
- \ to PatBic mode before redrawing the
- \ grow icon. This will cause the grow
- \ box lines to remain invisible.
- PatBic CALL PenMode
- THEN
- wptr CALL DrawGrowIcon
- CALL PenNormal
- THEN
- wptr CALL DrawControls
- wptr CALL EndUpdate
- saveport CALL SetPort ;
-
-
- \ ===== (RUN-ACTIVATE) ===================================================
-
- : (RUN-ACTIVATE) { | wptr edith -- }
- EVENT-RECORD Message + @ -> wptr
-
- \ If Mach2 is around this EditHandle will hold
- \ the handle to the Mach2 "Edit" menu.
- EditHandle @ -> edith
-
- \ Check for an activate event.
- EVENT-RECORD Modifiers + W@ ActivateMask AND
- IF
- \ The edit menu should be disabled when the
- \ Mach window becomes the active window.
- edith
- IF
- \ 0 means disable entire menu.
- edith 0 CALL DisableItem
- THEN
- ELSE
- \ Handle deactivate event.
- CurActivate @ windowKind + W@ L_EXT 0<
- IF
- \ A negative value in the windowKind field means
- \ the window is a system window, a desk accessory.
- \ Activate the "Edit" menu.
- edith
- IF
- \ 0 means enable entire menu.
- edith 0 CALL EnableItem
- THEN
- THEN
- THEN
- wptr CALL SetPort
- wptr GrowFlagOffset + C@
- IF
- wptr VBarOffset + @
- wptr HBarOffset + @ OR
- 0=
- IF
- \ If there is just a growbox, set pen
- \ to PatBic mode before redrawing the
- \ grow icon. This will cause the grow
- \ box lines to remain invisible.
- PatBic CALL PenMode
- THEN
- wptr CALL DrawGrowIcon
- CALL PenNormal
- THEN ;
-
-
- \ ===== "Vectored" Mouse Down Events =====================================
- \ ===== (CHECK-CONTROL) ==================================================
-
- : RunUserRoutine { wptr taskptr partcode chandle | address -- }
- taskptr ControlActionOffset + @ -> address
- address
- IF
- partcode
- chandle
- address EXECUTE
- THEN ;
-
- : MachTrackControl { wptr taskptr whichcontrol oldpartcode |
- point temppartcode -- flag }
- BEGIN
- CALL StillDown
- WHILE
- ^ point
- CALL GetMouse
-
- whichcontrol
- point
- CALL TestControl -> temppartcode
-
- temppartcode oldpartcode =
- IF
- whichcontrol
- temppartcode
- CALL HiliteControl
-
- wptr taskptr temppartcode whichcontrol
- RunUserRoutine
- ELSE
- whichcontrol
- 0
- CALL HiliteControl
- THEN
- REPEAT
- whichcontrol 0 CALL HiliteControl
-
- oldpartcode temppartcode =
- IF
- temppartcode
- ELSE
- 0
- THEN ;
-
- : MailData { chandle partcode taskptr -- }
- partcode taskptr ControlDataOffset + W!
- chandle taskptr ControlHandleOffset + ! ;
-
- : (CHECK-CONTROL) { wptr | saveport taskptr localpt whichcontrol partcode
- flag -- flag }
- 0 -> flag
- ^ saveport CALL GetPort
- wptr CALL SetPort
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ Look in the window record to see if this window
- \ has any controls.
- wptr controlList + @
- IF
- \ If this window has controls (1) convert the
- \ global mouse point coordinate found in the
- \ EVENT-RECORD to a local window mouse
- \ coordinate
- EVENT-RECORD Where + @ -> localpt
- ^ localpt CALL GlobalToLocal
-
- \ and (2) use FindControl to determine
- \ which control in the window experienced
- \ the interaction.
- localpt
- wptr
- ^ whichcontrol
- CALL FindControl -> partcode
-
- \ Check the value of the part code returned.
- \ If the mouse was pressed in an invisible,
- \ inactive, or no control, the part code will
- \ be zero. If the mouse was pressed in a
- \ visible, active control the part code will
- \ be a valid, non-zero part code value.
- partcode
- IF
- \ The mouse was clicked in a valid
- \ control, now follow the mouse to
- \ see if it was released in the control.
- -1 -> flag
- partcode InThumb =
- IF
- whichcontrol
- localpt
- 0
- CALL TrackControl -> partcode
- ELSE
- wptr
- taskptr
- whichcontrol
- partcode
- MachTrackControl -> partcode
- THEN
-
- \ Send the control interaction data
- \ to the task.
- whichcontrol partcode taskptr MailData
- THEN
- THEN
- THEN
- saveport CALL SetPort
- flag ;
-
-
- \ ===== (RUN-CONTENT) ====================================================
-
- : (RUN-CONTENT) { | wptr taskptr menulist -- }
- \ Is the window clicked in the active window ?
- EVENT-RECORD WhichWindow + @ -> wptr
- CALL FrontWindow wptr <>
- IF
- \ Initialize local variable.
- EmptyMenuBar @ -> menulist
-
- \ This window was not active, select it.
- wptr CALL SelectWindow
-
- \ If the window just selected has a
- \ menubar, display the menubar.
- \ Otherwise display and empty menubar.
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ Check the TaskMenuBar field of the
- \ task's user variable area. A non-zero
- \ value found there should be the address
- \ where the MenuList handle for the task's
- \ menubar is stored.
- taskptr TaskMenubarOffset + @
- ?DUP
- IF
- \ Display the task's custom menubar.
- @ -> menulist
- THEN
- THEN
- menulist CALL SetMenuBar
- CALL DrawMenuBar
- ELSE
- wptr (CHECK-CONTROL) DROP
- THEN ;
-
-
- \ ===== (RUN-DRAG) =======================================================
-
- : (RUN-DRAG) { | wptr taskptr -- }
- \ Check to see if the window whose drag region was clicked in
- \ is the current active window
- EVENT-RECORD WhichWindow + @ -> wptr
-
- CALL FrontWindow
- wptr
- <>
- IF
- \ If the window clicked in was not the active window
- \ first check to see if the command key was held down
- \ when the click occurred. If it was, we will not
- \ activate the window.
- EVENT-RECORD Modifiers + W@ CommandKeyMask AND
- 0=
- IF
- \ The command key was not down,
- \ select the window.
- wptr CALL SelectWindow
-
- \ If the window just selected has a
- \ menubar, display the menubar.
- \ Otherwise display and empty menubar.
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ Check the TaskMenuBar field of the
- \ task's user variable area. A non-zero
- \ value found there should be the address
- \ where the MenuList handle for the task's
- \ menubar is stored.
- taskptr TaskMenubarOffset + @
- DUP
- IF
- \ Display the task's custom menubar.
- @ CALL SetMenubar
- ELSE
- \ Display an empty menubar.
- DROP ( the zero TaskMenuBar)
- EmptyMenubar @ CALL SetMenubar
- THEN
- CALL DrawMenuBar
- THEN
- THEN
- THEN
- wptr \ Windowpointer for window to drag.
- EVENT-RECORD Where + @ \ Mouse location in global coordinates.
- ScreenRect \ Coordinates of this screen.
- CALL DragWindow ;
-
-
- \ ===== (RUN-GROWBOX) ====================================================
-
- : RedrawHVBars { wptr | vbarh hbarh -- }
- wptr VBarOffset + @ -> vbarh
- wptr HBarOffset + @ -> hbarh
-
- vbarh
- IF
- \ Hide the control before we redraw it.
- vbarh CALL HideControl
-
- \ Move the control to its new position.
- vbarh
- wptr portRect + 6 + W@ 15 - \ Horizontal destination.
- wptr portRect + W@ 1- \ Vertical destination.
- CALL MoveControl
-
- \ Resize the control
- vbarh
- 16 \ New control width.
- wptr portRect + 4+ W@ 13 - \ New control height.
- CALL SizeControl
-
- \ Now tell the window manager that the control
- \ area has already been redrawn
- vbarh @ ctrlRectOffset +
- CALL ValidRect
-
- \ Now the control can be made visible again.
- vbarh CALL ShowControl
- THEN
-
- hbarh
- IF
- hbarh CALL HideControl
-
- hbarh
- wptr portRect + 2+ W@ 1- \ Horiz. dest.
- wptr portRect + 4+ W@ 15 - \ Vert. dest.
- CALL MoveControl
-
- hbarh
- wptr portRect + 6 + W@ 13 - \ New width.
- 16 \ New height.
- CALL SizeControl
-
- hbarh @ ctrlRectOffset +
- CALL ValidRect
-
- hbarh CALL ShowControl
- THEN ;
-
- : EraseEdges { wptr | oldbot oldright rightbot lefttop -- }
- ^ lefttop ^ rightbot 2DROP
- wptr portRect + 4+ W@ -> oldbot
- wptr portRect + 6 + w@ -> oldright
-
- \ First, erase bottom edge of window.
- oldbot 16 - ^ lefttop W! \ Top of rect to be erased.
- 0 ^ lefttop 2+ W! \ Left of rect to be erased.
- oldbot ^ rightbot W! \ Bot. of rect to be erased.
- oldright ^ rightbot 2+ W! \ Right of rect to be erased.
- ^ lefttop CALL EraseRect
- ^ lefttop CALL InvalRect
-
- \ Next, erase right edge of window.
- 0 ^ lefttop W!
- oldright 16 - ^ lefttop 2+ W!
- oldbot ^ rightbot W!
- oldright ^ rightbot 2+ W!
- ^ lefttop CALL EraseRect
- ^ lefttop CALL InvalRect ;
-
- : (RUN-GROWBOX) { | wptr wrect oldheight
- rightbot lefttop newwidth newheight -- }
- EVENT-RECORD WhichWindow + @ -> wptr
- CALL FrontWindow wptr =
- IF
- wptr portRect + -> wrect
- wrect 4+ W@ wrect W@ - -> oldheight
- ScreenRect ^ lefttop 8 CMOVE
-
- wptr CALL SetPort
- wptr
- EVENT-RECORD Where + @
- ^ lefttop
- CALL GrowWindow -> newwidth
- ^ newwidth W@ -> newheight
- 0 ^ newwidth W!
-
- \ Is the window shorter ?
- newheight oldheight <
- IF
- wrect CALL InvalRect
- wrect CALL EraseRect
- THEN
-
- wptr EraseEdges
- wptr newwidth newheight -1 CALL SizeWindow
- wptr EraseEdges
-
- wptr RedrawHVBars
- THEN ;
-
-
- \ ===== (RUN-CLOSEBOX) ===================================================
-
- : (RUN-CLOSEBOX) { | wptr menuhandle taskptr -- }
- \ If the window is not the active window, leave.
- EVENT-RECORD WhichWindow + @ -> wptr
- CALL FrontWindow wptr =
- IF
- \ Initialize the contents of the menulist local variable.
- EmptyMenubar @ -> menuhandle
-
- \ Follow the mouse.
- \ If it is not released inside of the close box, leave.
- wptr
- EVENT-RECORD Where + @
- CALL TrackGoAway
- IF
- \ Hide the window and get the window
- \ pointer for the window immediately behind
- \ the window just closed, if any.
- wptr CALL HideWindow
- CALL FrontWindow -> wptr
- wptr
- IF
- \ If the window just uncovered has a
- \ menubar, display the menubar.
- \ Otherwise display and empty menubar.
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ Check the TaskMenuBar field of
- \ the task's user variable area.
- \ A non-zero value found there
- \ should be the address where the
- \ MenuList handle for the task's
- \ menubar is stored.
- taskptr TaskMenubarOffset + @
- ?DUP
- IF
- \ Display the task's
- \ custom menubar.
- @ -> menuhandle
- THEN
- THEN
- THEN
- menuhandle CALL SetMenuBar
- CALL DrawMenubar
- THEN
- THEN ;
-
-
- \ ===== (RUN-ZOOMIN) =====================================================
- \ ===== (RUN-ZOOMOUT) ====================================================
-
- : DoZoom { findcode | wptr taskptr -- }
- EVENT-RECORD WhichWindow + @ -> wptr
- CALL FrontWindow wptr =
- IF
- wptr CALL SetPort
-
- wptr
- EVENT-RECORD Where + @
- findcode
- CALL TrackBox
- IF
- wptr EraseEdges
-
- wptr findcode -1 CALL ZoomWindow
-
- wptr EraseEdges
- wptr RedrawHVBars
- THEN
- THEN ;
-
- : (RUN-ZOOMIN) ( - )
- InZoomIn DoZoom ;
-
- : (RUN-ZOOMOUT) ( - )
- InZoomOut DoZoom ;
-
-
- \ ===== MouseDown Event Dispatch Routine =================================
-
- : DoMouseDown { | findcode window taskptr -- }
- EVENT-RECORD Where + @
- ^ window
- CALL FindWindow -> findcode
-
- \ If click is in the menubar, we must specifically check for
- \ the frontwindow.
- findcode InMenuBar =
- IF
- CALL FrontWindow -> window
- THEN
-
- \ If click is in the growbox area, make sure the window has a
- \ growbox. If it doesn't, turn click into an in-content code.
- findcode InGrow =
- IF
- window GrowFlagOffset + C@ 0=
- IF
- InContent -> findcode
- THEN
- THEN
-
- \ We will only process this event if we have a valid windowpointer.
- window
- IF
- window EVENT-RECORD WhichWindow + !
- window CALL GetWRefCon -> taskptr
- taskptr
- IF
- findcode
- CASE
- InContent OF taskptr ContentOffset +
- @ EXECUTE ENDOF
- InDrag OF taskptr DragOffset +
- @ EXECUTE ENDOF
- InGrow OF taskptr GrowOffset +
- @ EXECUTE ENDOF
- InGoAway OF taskptr GoAwayOffset +
- @ EXECUTE ENDOF
- InZoomIn OF taskptr ZoomInOffset +
- @ EXECUTE ENDOF
- InZoomOut OF taskptr ZoomOutOffset +
- @ EXECUTE ENDOF
-
- InSysWindow OF Run-System ENDOF
- InMenuBar OF Run-Menubar ENDOF
- InDesk OF Run-Desk ENDOF
- ENDCASE
- ELSE
- findcode
- CASE
- InContent OF (RUN-CONTENT) ENDOF
- InDrag OF (RUN-DRAG) ENDOF
- InGrow OF (RUN-GROWBOX) ENDOF
- InGoAway OF (RUN-CLOSEBOX) ENDOF
- InZoomIn OF (RUN-ZOOMIN) ENDOF
- InZoomOut OF (RUN-ZOOMOUT) ENDOF
-
- InSysWindow OF Run-System ENDOF
- InMenuBar OF Run-Menubar ENDOF
- InDesk OF Run-Desk ENDOF
- ENDCASE
- THEN
- THEN ;
-
-
- \ ===== Modeless Dialog Event Dispatch Routine ===========================
- \ ===== (HandleDialog) ===================================================
-
- : (HandleDialog) { | thedialog itemhit wptr taskptr -- }
- \ This routine is called if a modeless dialog event has occurred.
- \ We know it is a modeless dialog event because a modal dialog
- \ would use its own event loop.
- \ If the event involves an enabled dialog item, DialogSelect
- \ will return TRUE and will return the dialog handle and
- \ the item number affected in the specified local variables.
- EVENT-RECORD ^ thedialog ^ itemhit CALL DialogSelect
- IF
- \ Which terminal task is using this modeless dialog ?
- CALL FrontWindow -> wptr
- wptr
- IF
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- \ If we were able to find the taskptr
- \ we can place the important information
- \ about the modeless dialog interaction
- \ in the appropriate user variable fields
- \ of the task's user variable area.
-
- \ The item number is a word length value.
- \ It will be returned in the upper 2 bytes
- \ of the local variable.
- ^ itemhit W@
- taskptr DialogDataOffset +
- W!
-
- thedialog
- taskptr DialogHandleOffset +
- !
- THEN
- THEN
- THEN ;
-
-
- \ ===== Event Dispatching Routines =======================================
-
- : HandleDialog { | taskptr wptr eventWhat -- }
- \ If it's a dialog event (and not an activate or update), the Message field of
- \ the EVENT-RECORD will not contain a window pointer, we must
- \ specifically ask for the window pointer.
- EVENT-RECORD What + W@ -> eventWhat
- eventWhat ActivateEvent = eventWhat UpdateEvent = OR
- IF
- EVENT-RECORD Message + @ -> wptr
- ELSE
- CALL FrontWindow -> wptr
- THEN
- wptr
- IF
- wptr CALL GetWRefCon -> taskptr
- taskptr
- IF
- taskptr DialogHookOffset + @ EXECUTE
- ELSE
- (HandleDialog)
- THEN
- THEN ;
-
- : DoUpdate { | taskptr -- }
- EVENT-RECORD Message + @ CALL GetWRefCon -> taskptr
- taskptr
- IF
- taskptr UpdateOffset + @ EXECUTE
- ELSE
- (RUN-UPDATE)
- THEN ;
-
- : DoActivate { | taskptr -- }
- EVENT-RECORD Message + @ CALL GetWRefCon -> taskptr
- taskptr
- IF
- taskptr ActivateOffset + @ EXECUTE
- ELSE
- (RUN-ACTIVATE)
- THEN ;
-
- : (RUN-SUSPEND/RESUME) { | wptr -- }
- CALL FrontWindow -> wptr
- EVENT-RECORD Message + @ EVENT-RECORD Modifiers + W!
- wptr EVENT-RECORD Message + !
- (RUN-ACTIVATE)
- ;
-
- : DoSuspendResume { | wptr taskptr -- }
- EVENT-RECORD Message + @ activateMask AND
- IF
- FALSE gInBackground! \ signal tasks to resume
- CALL FrontWindow -> wptr
- wptr 0= NOT
- IF ( you have a front window )
- wptr windowKind + W@ L_EXT 0<
- IF ( this is a desk accessory )
- EVENT-RECORD Modifiers + W@ \ post an activate event
- activateMask OR EVENT-RECORD Modifiers + W!
- EVENT-RECORD CALL SystemEvent DROP
- ELSE
- wptr CALL GetWRefCon ?DUP
- IF
- wptr CALL SetPort
- SuspendResumeOffset + @ EXECUTE
- THEN
- THEN
- THEN
- ELSE
- TRUE gInBackground! \ signal tasks to suspend
- CALL FrontWindow -> wptr
- wptr 0= NOT
- IF ( you have a front window )
- wptr windowKind + W@ L_EXT 0<
- IF ( this is a desk accessory )
- EVENT-RECORD Modifiers + W@ \ post a deactivate event
- $FFFE AND EVENT-RECORD Modifiers + W!
- EVENT-RECORD CALL SystemEvent DROP
- ELSE
- wptr CALL GetWRefCon ?DUP
- IF
- wptr CALL SetPort
- SuspendResumeOffset + @ EXECUTE
- THEN
- THEN
- THEN
- THEN
- ;
-
- : NextEvent ( - ) ;
-
-
- \ ===== (EVENT-TABLE =====================================================
-
- CREATE (EVENT-TABLE)
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (0) Null event.
- DC.L "DoMouseDown"-"(EVENT-TABLE)"-4 \ (1) Mouse down event.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (2) Mouse up event.
- DC.L "DoKeyDown"-"(EVENT-TABLE)"-4 \ (3) Key down event.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (4) Key up event.
- DC.L "DoKeyDown"-"(EVENT-TABLE)"-4 \ (5) Auto key event.
- DC.L "DoUpdate"-"(EVENT-TABLE)"-4 \ (6) Update event.
- DC.L "DoDisk"-"(EVENT-TABLE)"-4 \ (7) Disk event.
- DC.L "DoActivate"-"(EVENT-TABLE)"-4 \ (8) Activate event.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (9) Not used ?
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (10) Network event.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (11) Driver event.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (12) Appl-defined event #1.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (13) Appl-defined event #2.
- DC.L NextEvent-"(EVENT-TABLE)"-4 \ (14) Appl-defined event #3.
- DC.L "DoSuspendResume"-"(EVENT-TABLE)"-4 \ (15) osEvent.
-
- : HandleEvent { | eventcode baseaddr -- }
- EVENT-RECORD What + W@ -> eventcode
- (EVENT-TABLE) -> baseaddr
- baseaddr \ Base address.
- eventcode 4* \ Index into event table.
- + @ \ Offset to routine.
- baseaddr + \ Address of routine.
- EXECUTE ;
-
-
- \ ===== The Main Loop ====================================================
-
- : DialogEvent? ( - f )
- \ If the event is a dialog event which should be handled
- \ by our application (usually by being passed to DialogSelect),
- \ IsDialogEvent will return a true flag. If the event
- \ should be handled as a normal, non-dialog event, false
- \ will be returned.
- EVENT-RECORD CALL IsDialogEvent ;
-
- : GetNextEvent ( - f )
- \ If an event occurs which should be handled, GetNextEvent
- \ will return a true flag. The event code and any other
- \ event information will be returned in the EVENT-RECORD.
- \ Changed for MF support using Jorg's code 22 XI 88 - M. Anderegg
- ['] MFThere @
- CASE
- -1 OF \ Yes, we have WaitNextEvent.
- everyEvent EVENT-RECORD 1 0 WaitNextEvent
- ENDOF
- 0 OF \ No, we don't have WaitNextEvent.
- CALL SystemTask
- everyEvent EVENT-RECORD CALL GetNextEvent
- ENDOF
- ENDCASE
- ;
-
- : WNECheck ( - )
- \ This routine is executed the first time through the I/O Task
- \ main loop. It leaves the truth value for the presence of the
- \ WaitNextEvent Trap at MFThere. This modification is necessary,
- \ since Jorg's modification worked at compile time instead of run time.
- \ - M. Anderegg - 6 I 89.
-
- WNETrap# CALL GetTrapAddress
- UnkTrap# CALL GetTrapAddress
- =
- IF
- 0
- ELSE
- -1
- THEN
- ['] MFThere !
- ;
-
- \ ===== (IOTASK) =========================================================
-
- : (IOTask) { | dialogflag eventflag -- }
- WNECheck
- 0 gInBackground!
- BEGIN
- BEGIN
- GetNextEvent -> eventflag
- DialogEvent? -> dialogflag
-
- dialogflag
- IF
- HandleDialog
- ELSE
- eventflag
- IF
- HandleEvent
- THEN
- THEN
- eventflag 0=
- UNTIL
- PAUSE
- AGAIN ;
-
- ONLY FORTH
-
- NEW-IOTASK
-
- \ ===== END OF FILE ======================================================
- \ ========================================================================
- \ ========================================================================
-